home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRCATML.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  2KB  |  136 lines

  1. StdGrp        group    StdLib, StdData
  2. ;
  3. StdData        segment    para public 'sldata'
  4. ;
  5. scptr1        dd    ?
  6. strlen1        dw    ?
  7. scptr2        equ    2[bp]
  8. rtnadrs        dw    ?
  9. strlen2        dw    ?
  10. ;
  11. StdData        ends
  12. ;
  13. stdlib        segment    para public 'slcode'
  14.         assume    cs:StdGrp
  15. ;
  16.         extrn    sl_malloc:far
  17. ;
  18. ; strcatml-Computes the lengths of two strings pointed at by es:di and follow-
  19. ;      ing the call.  It then allocates storage for a string long enough
  20. ;      to hold the concatentation of these two strings.  Finally, it con-
  21. ;      catenates the two strings storing the resulting string into the new
  22. ;      buffer.  Returns ES:DI pointing at the new string.
  23. ;
  24. ; inputs:
  25. ;
  26. ;    ES:DI-    Points at the first string.
  27. ;
  28. ;    Return address points at the string to append.
  29. ;
  30. ;
  31. ; outputs:
  32. ;
  33. ;    ES:DI- Points at new string containing the concatenation of the
  34. ;           two strings.
  35. ;
  36. ;    carry=0 if no error.
  37. ;    carry=1 if strcat2 could not allocate enough memory to hold
  38. ;        the resulting string.
  39. ;
  40.         public    sl_strcatml
  41. ;
  42. sl_strcatml    proc    far
  43.         push    bp
  44.                 mov    bp, sp
  45.         push    cx
  46.         push    ax
  47.         push    ds
  48.         push    si
  49.         pushf
  50.         cld
  51. ;
  52. ; Save pointers to the strings
  53. ;
  54.         mov    word ptr StdGrp:scptr1, di
  55.         mov    word ptr StdGrp:scptr1+2, es
  56. ;
  57. ; Compute the length of the string following the call.
  58. ;
  59.         mov    al, 0
  60.         les    di, scptr2
  61.         mov    cx, 0ffffh
  62.     repne    scasb
  63.         mov    StdGrp:rtnadrs, di        ;Save return address
  64.         neg    cx
  65.         dec    cx
  66.         mov    StdGrp:StrLen2, cx
  67. ;
  68. ; Find the end of the first string:
  69. ;
  70.         les    di, StdGrp:scptr1
  71.         mov    cx, 0ffffh
  72.     repne    scasb
  73.         neg    cx
  74.         dec    cx
  75.         dec    cx
  76.         mov    StdGrp:StrLen1, cx
  77. ;
  78. ; Malloc the appropriate storage:
  79. ;
  80.         add    cx, StdGrp:StrLen2
  81.         call    sl_malloc
  82.         jc    BadStrCat2
  83. ;
  84. ; Save ptr to dest
  85. ;
  86.         push    es
  87.         push    di        
  88. ;
  89. ; Copy the strings:
  90. ;
  91.         lds    si, StdGrp:scptr1
  92.         mov    cx, StdGrp:strlen1
  93.         shr    cx, 1
  94.         jnc    cs1
  95.         lodsb
  96.         stosb
  97. cs1:    rep    movsw
  98.         lds    si, scptr2
  99.         mov    cx, StdGrp:strlen2
  100.         shr    cx, 1
  101.         jnc    cs2
  102.         lodsb
  103.         stosb
  104. cs2:    rep    movsw
  105. ;
  106.         mov    ax, StdGrp:rtnadrs
  107.         mov    scptr2, ax
  108.         pop    di
  109.         pop    es
  110.         popf
  111.         pop    si
  112.         pop    ds
  113.         pop    ax
  114.         pop    cx
  115.         pop    bp
  116.         clc
  117.         ret
  118. ;
  119. BadStrCat2:    mov    es, word ptr StdGrp:scptr1+2
  120.         mov    si, word ptr StdGrp:scptr1
  121.         mov    ax, StdGrp:rtnadrs
  122.         mov    scptr2, ax
  123.         popf
  124.         pop    di
  125.         pop    ds
  126.         pop    ax
  127.         pop    cx
  128.         pop    bp
  129.         stc
  130.         ret
  131. sl_strcatml    endp
  132. ;
  133. ;
  134. stdlib        ends
  135.         end
  136.